// 引入react
import * as React from 'react';
import {StyleSheet, View, Text, ScrollView, TouchableOpacity} from 'react-native';
import {HeaderTitle} from '../../../../componet/settingComponent/HeaderTitle';
import AllStyle from '../../../../style';
import {SafeAreaView} from 'react-native-safe-area-context';
import {CardItem} from '../../../../componet/settingComponent/CardItem';
import {BrLine} from '../../../../componet/settingComponent/BrLine';
import {Toast} from '../../../../utils/Toast';
import {getUserInfo} from '../../../../api/user';
import {Loading} from '../../../../utils/Loading';

/**
 * @Description:
 * @author TangYong
 * @date 2023/3/13
 */
export class MySetting extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            user: {
                'userId': null,
                'username': '',
                'password': '',
                'salt': '',
                'email': '',
                'mobile': '',
                'identityCard': null,
                'status': 1,
                'roleIdList': null,
                'createUserId': 1,
                'createTime': '',
            },
        };
    }

    //生命周期：组件挂载后
    componentDidMount() {
        this.init();
    }

    //方法
    back = () => {
        // alert( this.props.route.params.routePathName)
        // return
        this.props.navigation.goBack();

    };
    ShowMsg = () => {
        Toast.showWarning('个人信息不允许修改，请在pc端修改');
    };
    goto = (name, params) => {

        const route = {
            name: name,
            params: {
                routePathName: this.props.route.name,
                ...params,
            },

        };
        this.props.navigation.navigate(route);
    };
    init = () => {
        Loading.show();
        getUserInfo().then(res => {

            let {user} = res;
            this.setState({user});

        }).catch(err => {
                Toast.showWarning(err.toString());
                Loading.hidden();
            },
        ).finally(() => {
            Loading.hidden();
        });
    };

    //DOM
    render() {
        return (
            <SafeAreaView edges={['top', 'left', 'right']} style={{flex: 1, backgroundColor: '#FFF'}}>
                <View style={AllStyle.container}>
                    <HeaderTitle goBack={() => {
                        this.back();
                    }} headtitle={'个人信息'}
                    />

                    <ScrollView style={AllStyle.padding15}>
                        <View style={AllStyle.card}>
                            <TouchableOpacity onPress={() => {
                                this.ShowMsg();
                                // this.goto('setUserName',
                                //     {Name: '',title: '设置姓名'});
                            }}>
                                <CardItem title='姓名'
                                          value={this.state.user.username}></CardItem>
                            </TouchableOpacity>
                            <BrLine></BrLine>
                            <TouchableOpacity onPress={() => {
                                this.ShowMsg();
                                // this.goto('setUserName',
                                //     {Name: '',title: '设置姓名'});
                            }}>
                                <CardItem title={'手机'} value={this.state.user.mobile}></CardItem>
                            </TouchableOpacity>
                            <BrLine></BrLine>
                            <TouchableOpacity onPress={() => {
                                this.ShowMsg();
                                // this.goto('setUserName',
                                //     {Name: '',title: '设置姓名'});
                            }}>
                                <CardItem title={'邮箱'} value={this.state.user.email}></CardItem>
                            </TouchableOpacity>
                        </View>
                        <View style={AllStyle.card}>
                            <TouchableOpacity onPress={() => {
                                this.goto('setPassword',
                                    {Name: '', title: '修改密码'});
                            }}>
                                <CardItem title='修改密码'
                                          value={''}></CardItem>
                            </TouchableOpacity>

                        </View>
                    </ScrollView>
                </View>
            </SafeAreaView>
        );
    }

}

const style = StyleSheet.create({
    //样式
});
